<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('福利地区配置')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="ComPidorDepTid" name="ComPidorDepTid">
                    <div class="select-list">
                        <ul>
                            <li>
                                代码：<input type="text" name="code"/>
                            </li>
                            <li>
                                名称：<input type="text" name="title"/>
                            </li>
                            <li>
                                城市：
                                <select id="payCity" name="payCity">

                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:user:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:user:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>

<script th:inline="javascript">
    var prefix = ctx + "welfare/region/welfareRegionConfig";
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        queryData();
        getEcdCity();
    });

    function queryData() {
        var options = {
            code: "id",
            uniqueId: "id",
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            height: $(window).height() - 120,
            modalName: "福利地区",
            columns: [{
                checkbox: true
            }, {
                field: 'id',
                title: '*序号',
            },
                {
                    field: 'code',
                    title: '代码'
                },
                {
                    field: 'title',
                    title: '名称'
                },
                {
                    title: '？失效',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '？默认',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return defaultTools(row);
                    }
                },
                {
                    field: 'payCityName',
                    title: '*薪资城市'
                },
                {
                    field: 'remark',
                    title: '备注'
                }]
        };
        $.table.init(options);
    }


    function getEcdCity() {
        var html;
        $.ajax({
            async: false,
            url: ctx + "ecdCity/getEcdCity",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#payCity").empty();
                var arry = data;
                html += "<option value='0'>"
                    + '所有城市'
                    + "</option>";
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].id
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#payCity").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }


    /* 福利地区状态显示 */
    function statusTools(row) {
        if (row.isDisabled == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 福利地区管理-停用 */
    function disable(id) {
        console.log(id);
        $.modal.confirm("确认要停用福利地区吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isDisabled": 1});
        })
    }

    /* 福利地区启用 */
    function enable(id) {
        console.log(id);
        $.modal.confirm("确认要启用福利地区吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "isDisabled": 0});
        })
    }

    /* 是否默认 */
    function defaultTools(row) {
        if (row.isDefault == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disableDefault(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="enableDefault(\'' + row.id + '\')"></i> ';
        }
    }

    /* 取消默认 */
    function disableDefault(id) {
        $.modal.confirm("确认要取消默认？", function () {
            $.operate.post(prefix + "/changeDefault", {"id": id, "isDefault": 1});
        })
    }

    /* 福利地区启用 */
    function enableDefault(id) {
        $.modal.confirm("确认要启用默认", function () {
            $.operate.post(prefix + "/changeDefault", {"id": id, "isDefault": 0});
        })
    }
</script>
</body>
</html>